// pages/zhaoping/zhaoping.js

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    xueshen: true,
    txtlist: [],
    POST_WORK: '', //岗位
    STUDENT_PHONE: '', //手机号
    POST_SALARY: '', //期望薪资
    POST_NAME: '', //姓名
    modalHidden: true,
    guanggaotanchuang: true,
    shangwang: '',
    xxkuang: true,
    xingbie: true,

    POST_ADD: '',
    xinbiexuan: [{
        xinbie: '男'
      },
      {
        xinbie: '女'
      },
    ],

    shifou: [{
        xinbie: '是'
      },
      {
        xinbie: '否'
      },
    ],


    jiankang: '',

    POST_IDCARD: '',

    POST_MONEY: '',

    OPEN_ID: '',

    shijian: true,

    flag: true, //设置节流
    choujiang: true,
    zaicijinru: true,

    wangdian: '',
    POST_SEX: '',
    POST_AGE: '',
    POST_QX: '',
    POST_ADD: '',
    shangwang: '',
    sbwngdian: true,
    wangdiany: true,

    WALKING_AGE: '',
    flag: true, //设置节流
    flagaa: true, //设置节流
    // PRIZE_ID:5,

    fuwu: false,
    checked:'',

  },





  fuwu() {
    // this.setData({ show: true });
    this.setData({
      fuwu: !this.data.fuwu
    })
  },



  fuxk(event) {
    console.log(event.detail);
    this.setData({
      checked: event.detail,
    });
  },







  chuxian() {
    this.setData({
      xxkuang: false,
    })
  },




























  wangdianshagn() {

    if (this.data.POST_ADD == '') {
      wx.showToast({
        title: '请先选择县区！',
        icon: 'none',
        duration: 1500
      })
    } else {

      this.setData({
        sbwngdian: false
      })
    }



  },

  //网点选择
  wangji() {
    this.setData({
      wangdiany: false
    })
  },

  xwang(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.wangname);

    this.setData({
      POST_ADD: e.currentTarget.dataset.item.L3name,
      wangdiany: true,
      L3code: e.currentTarget.dataset.item.L3code,
      POST_QX: '',
    })
    this.regionwangdian()
  },

  region() {
    wx.request({
      url: app.globalData.interface+'/ankangdabiao/API_5515_userQueryQuXian',
      method: 'POST',
      data: {
        L2code: 61000026,
        OPEN_ID: this.data.openid,
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data.data);
        this.setData({
          wangdian: res.data.data,
        })

      }
    })
  },



  regionwangdian() {
    wx.request({
      url: app.globalData.interface+'/ankangdabiao/API_5517_userQueryWangDian',
      method: 'POST',
      data: {
        L3code: this.data.L3code,
        OPEN_ID: this.data.openid,
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data.data);
        this.setData({
          shangwang: res.data.data,
        })

      }
    })
  },






  wangshang(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.L4name);
    console.log(e.currentTarget.dataset.item.EMPLOYEE_ID);

    this.setData({
      POST_QX: e.currentTarget.dataset.item.L4name,
      sbwngdian: true,
      EMPLOYEE_ID: e.currentTarget.dataset.item.EMPLOYEE_ID,


    })
  },





  handleInput(e) {
    let value = this.validateNumber(e.detail.value)

    console.log(value);
    this.setData({
      POST_MONEY: value
    })
  },
  validateNumber(val) {
    return val.replace(/\D/g, '')
  },




  back() {
    wx.navigateBack({
      delta: 1
    })
  },







  xinbie() {
    this.setData({
      xingbie: false
    })
  },


  xin(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.xinbie);

    this.setData({
      POST_SEX: e.currentTarget.dataset.item.xinbie,
      xingbie: true,

    })
  },




  dianshi() {
    this.setData({
      shijian: false
    })
  },


  fou(e) {
    console.log(e);
    console.log(e.currentTarget.dataset.item.xinbie);

    this.setData({
      jiankang: e.currentTarget.dataset.item.xinbie,
      shijian: true,

    })
  },










  //验证手机号
  mobileInput(e) {
    let value = e.detail.value.replace(/\D/g, '')
    this.setData({
      mobile: value,
    })
    var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (this.data.mobile.length == 0) {
      wx.showToast({
        title: '输入的手机号为空，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        mobileFormat: false,
      })
    } else if (this.data.mobile.length < 11) {

      wx.showToast({
        title: '手机号长度有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        POST_PHONE: '',
        mobileFormat: false,
      })

    } else if (!myreg.test(this.data.mobile)) {
      wx.showToast({
        title: '手机号有误，请重新输入！',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        POST_PHONE: '',
        mobileFormat: false,
      })

    } else {
      this.setData({
        mobileFormat: true,
      })
    }
  },




  bouut() {

    if (this.data.flagaa) {

      this.data.flagaa = false




      this.setData({
        openid: app.globalData.openid,
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        session_key: app.globalData.session_key,
      })

      console.log(this.data.openid);
      if (this.data.WALKING_AGE == "" || this.data.POST_QX == "" || this.data.POST_ADD == "" || this.data.POST_NAME == "" || this.data.STUDENT_PHONE == "" || this.data.openid == "" || this.data.POST_SEX == "" || this.data.jiankang == "") {
        wx.showToast({
          title: '请完善信息',
          icon: 'none',
          duration: 1500
        })
        console.log(this.data.POST_NAME);
        console.log(this.data.STUDENT_PHONE);
        console.log(this.data.openid);
        console.log(this.data.POST_IDCARD);
        console.log(this.data.POST_SEX);
        console.log(this.data.POST_MONEY);

      } else if (this.data.checked == false) {
        wx.showToast({
          title: "请勾选用户协议",
          icon: "none",
          duration: 2000
        })
  
      } else {
        wx.request({
          url: app.globalData.interface+'/shangluoTicket/API_5901_WalkingUserAdd',
          method: 'POST',
          data: {

            WALKING_NAME: this.data.POST_NAME,
            WALKING_IDCARD: this.data.STUDENT_PHONE,
            WALKING_AGE: this.data.WALKING_AGE,


            WALKING_SEX: this.data.POST_SEX,
            WALKING_HEALTH: this.data.jiankang,
            ENROLL_ADD: this.data.POST_ADD + '_' + this.data.POST_QX,
            OPEN_ID: this.data.openid, //用户OPEN_ID
            session_key: this.data.session_key,
            OPEN_UUID: this.data.jiami,

          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: res => {
            console.log(res.data);
            let that = this

            if (res.data.result == "error") {
              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后
                  } else { //这里是点击了取消以后
                    console.log('用户点击取消')
                  }
                }
              })
            } else {
              wx.showModal({
                title: '温馨提示',
                content: res.data.data,
                success: function (res) {
                  if (res.confirm) { //这里是点击了确定以后
                    that.setData({
                      xxkuang: true,


                    })
                  } else { //这里是点击了取消以后
                    console.log('用户点击取消')
                    that.setData({
                      xxkuang: true,


                    })
                  }
                }
              })


            }

          }
        })
      }


      setTimeout(() => {
        this.data.flagaa = true
      }, 3500)


    }


  },



  shuju() {
    this.setData({
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
    })

    wx.request({
      url: app.globalData.interface+'/shangluoTicket/API_5907_WalkingUserSelect',
      method: 'post',
      data: {


        OPEN_UUID: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        session_key: app.globalData.session_key,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {



        console.log(res.data.data);

        if (res.data.baoming == '1') {
          wx.navigateTo({
            url: '../../pages/shangluoweixinbushu/shangluoweixinbushu',
  
          })
        }else{
          this.setData({
            WALKING_ID: res.data.data.WALKING_ID,
            zongshuju: res.data.data,
  
  
          })
  

        }


      }
    })
  },







  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {

    this.setData({

      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      CUSTOMER_ID: app.globalData.CUSTOMER_ID,

    });

    console.log(this.data.OPEN_ID);



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {


    this.region()


    setTimeout(() => {
      this.shuju()
    }, 500)



  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: '财富步步为赢 健康久久相伴',
      desc: '快来参与吧！',
      path: `/pages/shangluoweixinbushuzhuce/shangluoweixinbushuzhuce`,
      imageUrl: this.data.GOODS_IMG,
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == 'shareAppMessage:ok') {
          console.log('444444444444455555555');
        }
      },
      fail: function () {
        // 转发失败之后的回调
        if (res.errMsg == 'shareAppMessage:fail cancel') {
          // 用户取消转发
        } else if (res.errMsg == 'shareAppMessage:fail') {
          // 转发失败，其中 detail message 为详细失败信息
        }
      },
      complete: {
        // 转发结束之后的回调（转发成不成功都会执行）
      }
    }

  },



})